package com.lkc.controller;

import com.lkc.domain.ResponseResult;
import com.lkc.domain.entity.User;
import com.lkc.service.SystemService;
import com.lkc.utils.VerifyCodeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * @Title: SystemLoginController
 * @Author 椰咩咩
 * @Package com.lkc.controller
 * @Date 2022/12/23 13:51
 * @description: 系统控制层
 */
@RestController
public class SystemController {

    @Autowired
    private SystemService systemService;

    @PostMapping("/user/login")
    public ResponseResult login(@RequestBody User user) {
        return systemService.login(user);
    }

    @GetMapping("/getMenu")
    public ResponseResult getMenu() {
        return systemService.getMenu();
    }

    @GetMapping("/getRouters")
    public ResponseResult getRouters() {
        return systemService.getRouters();
    }

    @RequestMapping(value = "/verifyCode/{num}", method = RequestMethod.GET)
    public void verifyCode(HttpSession session, HttpServletResponse response) throws IOException {
        //生成验证码
        String code = VerifyCodeUtils.generateVerifyCode(4);
        //验证码存入图片
        ServletOutputStream os = response.getOutputStream();
        //设置响应类型
        response.setContentType("image/png");
        VerifyCodeUtils.outputImage(180, 60, os, code);
    }
}
